from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-06 14:02:23.213088
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 06, Aug, 2022
Time: 14:02:28
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.0485
Nobs: 740.000 HQIC: -50.3928
Log likelihood: 9365.12 FPE: 1.04927e-22
AIC: -50.6088 Det(Omega_mle): 9.29870e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296889 0.055702 5.330 0.000
L1.Burgenland 0.107751 0.036902 2.920 0.004
L1.Kärnten -0.106874 0.019557 -5.465 0.000
L1.Niederösterreich 0.206737 0.076965 2.686 0.007
L1.Oberösterreich 0.109948 0.075202 1.462 0.144
L1.Salzburg 0.254349 0.039432 6.450 0.000
L1.Steiermark 0.041965 0.051456 0.816 0.415
L1.Tirol 0.108500 0.041740 2.599 0.009
L1.Vorarlberg -0.062329 0.035897 -1.736 0.083
L1.Wien 0.048053 0.066527 0.722 0.470
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058262 0.116402 0.501 0.617
L1.Burgenland -0.031988 0.077116 -0.415 0.678
L1.Kärnten 0.047029 0.040870 1.151 0.250
L1.Niederösterreich -0.175823 0.160836 -1.093 0.274
L1.Oberösterreich 0.407397 0.157152 2.592 0.010
L1.Salzburg 0.287881 0.082403 3.494 0.000
L1.Steiermark 0.107733 0.107530 1.002 0.316
L1.Tirol 0.311389 0.087225 3.570 0.000
L1.Vorarlberg 0.025307 0.075014 0.337 0.736
L1.Wien -0.029762 0.139023 -0.214 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189252 0.028596 6.618 0.000
L1.Burgenland 0.090165 0.018945 4.759 0.000
L1.Kärnten -0.008856 0.010040 -0.882 0.378
L1.Niederösterreich 0.260107 0.039512 6.583 0.000
L1.Oberösterreich 0.138670 0.038607 3.592 0.000
L1.Salzburg 0.045449 0.020244 2.245 0.025
L1.Steiermark 0.021283 0.026416 0.806 0.420
L1.Tirol 0.093228 0.021428 4.351 0.000
L1.Vorarlberg 0.055540 0.018428 3.014 0.003
L1.Wien 0.116336 0.034153 3.406 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108114 0.029030 3.724 0.000
L1.Burgenland 0.045692 0.019233 2.376 0.018
L1.Kärnten -0.014009 0.010193 -1.374 0.169
L1.Niederösterreich 0.189531 0.040112 4.725 0.000
L1.Oberösterreich 0.302419 0.039193 7.716 0.000
L1.Salzburg 0.109818 0.020551 5.344 0.000
L1.Steiermark 0.104367 0.026818 3.892 0.000
L1.Tirol 0.105768 0.021754 4.862 0.000
L1.Vorarlberg 0.068514 0.018708 3.662 0.000
L1.Wien -0.021005 0.034672 -0.606 0.545
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126606 0.052911 2.393 0.017
L1.Burgenland -0.050000 0.035053 -1.426 0.154
L1.Kärnten -0.040684 0.018577 -2.190 0.029
L1.Niederösterreich 0.170435 0.073108 2.331 0.020
L1.Oberösterreich 0.138173 0.071433 1.934 0.053
L1.Salzburg 0.288823 0.037456 7.711 0.000
L1.Steiermark 0.035728 0.048878 0.731 0.465
L1.Tirol 0.163368 0.039648 4.120 0.000
L1.Vorarlberg 0.101012 0.034098 2.962 0.003
L1.Wien 0.068629 0.063193 1.086 0.277
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055990 0.042050 1.331 0.183
L1.Burgenland 0.039397 0.027858 1.414 0.157
L1.Kärnten 0.051117 0.014764 3.462 0.001
L1.Niederösterreich 0.218420 0.058102 3.759 0.000
L1.Oberösterreich 0.295799 0.056771 5.210 0.000
L1.Salzburg 0.043643 0.029768 1.466 0.143
L1.Steiermark 0.000618 0.038845 0.016 0.987
L1.Tirol 0.143336 0.031510 4.549 0.000
L1.Vorarlberg 0.072110 0.027099 2.661 0.008
L1.Wien 0.080414 0.050222 1.601 0.109
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173506 0.050277 3.451 0.001
L1.Burgenland -0.002401 0.033309 -0.072 0.943
L1.Kärnten -0.062560 0.017653 -3.544 0.000
L1.Niederösterreich -0.077656 0.069469 -1.118 0.264
L1.Oberösterreich 0.190075 0.067878 2.800 0.005
L1.Salzburg 0.057973 0.035592 1.629 0.103
L1.Steiermark 0.234490 0.046445 5.049 0.000
L1.Tirol 0.498566 0.037675 13.233 0.000
L1.Vorarlberg 0.045154 0.032401 1.394 0.163
L1.Wien -0.054860 0.060047 -0.914 0.361
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160134 0.057971 2.762 0.006
L1.Burgenland -0.008119 0.038406 -0.211 0.833
L1.Kärnten 0.065745 0.020354 3.230 0.001
L1.Niederösterreich 0.205010 0.080101 2.559 0.010
L1.Oberösterreich -0.066264 0.078266 -0.847 0.397
L1.Salzburg 0.208738 0.041039 5.086 0.000
L1.Steiermark 0.122091 0.053553 2.280 0.023
L1.Tirol 0.073059 0.043441 1.682 0.093
L1.Vorarlberg 0.120352 0.037359 3.221 0.001
L1.Wien 0.120684 0.069237 1.743 0.081
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.359570 0.033294 10.800 0.000
L1.Burgenland 0.007184 0.022057 0.326 0.745
L1.Kärnten -0.023696 0.011690 -2.027 0.043
L1.Niederösterreich 0.215013 0.046003 4.674 0.000
L1.Oberösterreich 0.199720 0.044949 4.443 0.000
L1.Salzburg 0.043741 0.023569 1.856 0.063
L1.Steiermark -0.013210 0.030756 -0.430 0.668
L1.Tirol 0.104761 0.024949 4.199 0.000
L1.Vorarlberg 0.070864 0.021456 3.303 0.001
L1.Wien 0.038054 0.039764 0.957 0.339
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039433 0.139367 0.191381 0.150883 0.117374 0.103063 0.063346 0.216518
Kärnten 0.039433 1.000000 -0.007544 0.132381 0.039234 0.094227 0.433002 -0.053933 0.097343
Niederösterreich 0.139367 -0.007544 1.000000 0.333485 0.142014 0.292763 0.095960 0.179480 0.312909
Oberösterreich 0.191381 0.132381 0.333485 1.000000 0.228887 0.324948 0.175955 0.165907 0.260797
Salzburg 0.150883 0.039234 0.142014 0.228887 1.000000 0.142806 0.112823 0.145270 0.123695
Steiermark 0.117374 0.094227 0.292763 0.324948 0.142806 1.000000 0.146094 0.137130 0.071077
Tirol 0.103063 0.433002 0.095960 0.175955 0.112823 0.146094 1.000000 0.112364 0.142792
Vorarlberg 0.063346 -0.053933 0.179480 0.165907 0.145270 0.137130 0.112364 1.000000 -0.000662
Wien 0.216518 0.097343 0.312909 0.260797 0.123695 0.071077 0.142792 -0.000662 1.000000